version: "3.8"
services:
  seckill-api:
    image: seckill_api:0.2
    deploy:
      mode: replicated
      replicas: 1
      endpoint_mode: vip
      resources:
        limits:
          cpus: '0.3'
        reservations:
          cpus: '0.01'
      update_config:
        parallelism: 2
        order: start-first
      rollback_config:
        parallelism: 2
        order: start-first
    depends_on:
      - kafka
    entrypoint: "python main.py"
    environment:
      - KAFKA_SERVER=test_kafka 
      - KAFKA_MAX_RETRIES=500  
      - KAFKA_RETRY_DELAY=5  
  kafka-compensation:
    image: seckill_api:0.2
    deploy:
      mode: replicated
      replicas: 1
      endpoint_mode: vip
      resources:
        limits:
          cpus: '0.3'
        reservations:
          cpus: '0.01'
      update_config:
        parallelism: 2
        order: start-first
      rollback_config:
        parallelism: 2
        order: start-first
    depends_on:
      - kafka
    entrypoint: "python kafka_compensation.py"
    environment:
      - KAFKA_SERVER=test_kafka 
      - KAFKA_MAX_RETRIES=500  
      - KAFKA_RETRY_DELAY=5  
  kafka-consumer:
    image: seckill_api:0.2
    deploy:
      mode: replicated
      replicas: 1
      endpoint_mode: vip
      resources:
        limits:
          cpus: '0.3'
        reservations:
          cpus: '0.01'
      update_config:
        parallelism: 2
        order: start-first
      rollback_config:
        parallelism: 2
        order: start-first
    depends_on:
      - kafka
    entrypoint: "python kafka_consumer.py"
    environment:
      - KAFKA_SERVER=test_kafka 
      - KAFKA_MAX_RETRIES=500  
      - KAFKA_RETRY_DELAY=5  
  kafka:
    image: bitnami/kafka:3.9.0-debian-12-r12
    environment:
      - ALLOW_PLAINTEXT_LISTENER=yes
      - KAFKA_CFG_NODE_ID=1
      - KAFKA_CFG_PROCESS_ROLES=controller,broker
      - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@kafka:9093
      - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
      - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093
      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092
      - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT
    ports:
      - "9092:9092"
      - "9093:9093" 
networks:
  my_overlay_net:
    driver: overlay
    attachable: true